import java.util.Arrays;

public class Solution {
    public static void main(String[] args) {
        System.out.println(reverse(1534236469));
    }
    public static int reverse(int x) {
        try {
            String str=String.valueOf(x);//转化为string
            StringBuilder res = new StringBuilder();
            boolean flag=true;//标志位
            if(x>0){
                char[] chars = new char[str.length()];//数组
                //遍历转化为数组
                for (int i = 0; i < str.length(); i++) {
                    chars[i] = str.charAt(i);
                }

                //从后往前遍历数组
                for (int i = chars.length-1; i >=0 ; i--) {
                    if (chars[i]!='0'&&flag){//末尾不等于0
                        res.append(chars[i]);
                        flag=false;
                    }else {
                        res.append(chars[i]);
                    }
                }
                return Integer.parseInt(res.toString());
            }else if(x<0){
                str=str.substring(1, str.length());
                char[] chars = new char[str.length()];//数组
                //遍历转化为数组
                for (int i = 0; i < str.length(); i++) {
                    chars[i] = str.charAt(i);
                }

                //从后往前遍历数组
                for (int i = chars.length-1; i >=0 ; i--) {
                    if (chars[i]!='0'&&flag){//末尾不等于0
                        res.append(chars[i]);
                        flag=false;
                    }else {
                        res.append(chars[i]);
                    }
                }
                res.insert(0, '-');
                return Integer.parseInt(res.toString());
            }else{
                return x;//0
            }
        } catch (NumberFormatException e) {
            e.printStackTrace();
            return 0;
        }
    }
}
